package com.admin.rxandroidtest.retrofit;

import android.util.Log;
import android.view.View;

import com.admin.rxandroidtest.BaseViewActivity;
import com.admin.rxandroidtest.ConnectionService;
import com.admin.rxandroidtest.RequestListener;
import com.admin.rxandroidtest.Result;

import retrofit2.Call;

public class RetrofitActivity extends BaseViewActivity {

    @Override
    public void initEvent() {
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvr.setText("");
                pb1.setVisibility(View.VISIBLE);
                getResult();
            }
        });
    }

    public void getResult(){
        Call<Result> call=RetrofitServer.getInstance().createCall(ConnectionService.class).getBlogGson("us");
        RetrofitServer.getInstance().enqueue(call, 1, new RequestListener<Result>() {
            @Override
            public void onResquestSuccess(Result result) {
                System.out.println(result);
                tvr.setText(result.toString());
                pb1.setVisibility(View.GONE);
            }

            @Override
            public void onResquestError(int requestCode, int errorCode, String message) {
                Log.d("TAG", "onResquestError: "+message);
            }
        });
    }

}
